﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;

namespace ADC.BL
{
    public class SupportFactory
    {
        public static List<Support> GetAll()
        {
            var db = new dbADCEntities();
            return db.Supports.ToList();
        }

        public static Support GetByID(int supportID)
        {
            var db = new dbADCEntities();
            return db.Supports.Where(g => g.SupportID == supportID).FirstOrDefault();
        }

        public static List<Support> GetByType(byte type) {
            var db = new dbADCEntities();
            return db.Supports.Where(g=> g.Type == type).ToList();
        }

        public static int Update(Support support)
        {
            var db = new dbADCEntities();
            var objSupport = db.Supports.Where(g => g.SupportID == support.SupportID).FirstOrDefault();
            objSupport.Name = support.Name;
            objSupport.Description = support.Description;
            objSupport.NickName = support.NickName;
            objSupport.Type = support.Type;
            return db.SaveChanges();
        }

        public static int Insert(Support support)
        {
            var db = new dbADCEntities();
            db.AddToSupports(support);
            return db.SaveChanges();
        }

        public static int Delete(int supportID)
        {
            var db = new dbADCEntities();
            var support = db.Supports.Where(g => g.SupportID == supportID).FirstOrDefault();
            db.DeleteObject(support);
            return db.SaveChanges();
        }
    }
}
